package com.liangwj.springbootdesignpatterns.structureTypePatterns.adapter.demo_1.impl;

import com.liangwj.springbootdesignpatterns.structureTypePatterns.adapter.demo_1.AdvancedMediaPlayer;
import com.liangwj.springbootdesignpatterns.structureTypePatterns.adapter.demo_1.MediaPlayer;

/**
 * <b>Description:</b> MediaPlayer接口的适配器类 <br/>
 * @author Lingwenjun
 * @date 2019/1/23-14:05
 * @version 1.0
 */
public class MediaAdapter implements MediaPlayer {

    //对象适配器模式
    private AdvancedMediaPlayer advancedMediaPlayer;

    //construct
    public MediaAdapter(String audioType) {
        if (("vlc").equalsIgnoreCase(audioType)) {
            advancedMediaPlayer = new VlcPlayer();
        } else if (("mp4").equalsIgnoreCase(audioType)) {
            advancedMediaPlayer = new Mp4Player();
        }
    }

    @Override
    public void play(String audioType, String filename) {
        if (("vlc").equalsIgnoreCase(audioType)) {
            advancedMediaPlayer.playVlc(filename);
        } else if (("mp4").equalsIgnoreCase(audioType)) {
            advancedMediaPlayer.playMp4(filename);
        }
    }
}
